home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_kernel_source / FS / INODE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-17  |  18.6 KB  |  807 lines

  1. /*
  2.  * linux/fs/inode.c
  3.  *
  4.  * (C) 1997 Linus Torvalds
  5.  */
  6.  
  7. #include <linux/fs.h>
  8. #include <linux/string.h>
  9. #include <linux/mm.h>
  10. #include <linux/dcache.h>
  11. #include <linux/init.h>
  12. #include <linux/quotaops.h>
  13.  
  14. /*
  15.  * New inode.c implementation.
  16.  *
  17.  * This implementation has the basic premise of trying
  18.  * to be extremely low-overhead and SMP-safe, yet be
  19.  * simple enough to be "obviously correct".
  20.  *
  21.  * Famous last words.
  22.  */
  23.  
  24. #define INODE_PARANOIA 1
  25. /* #define INODE_DEBUG 1 */
  26.  
  27. /*
  28.  * Inode lookup is no longer as critical as it used to be:
  29.  * most of the lookups are going to be through the dcache.
  30.  */
  31. #define HASH_BITS    8
  32. #define HASH_SIZE    (1UL << HASH_BITS)
  33. #define HASH_MASK    (HASH_SIZE-1)
  34.  
  35. /*
  36.  * Each inode can be on two separate lists. One is
  37.  * the hash list of the inode, used for lookups. The
  38.  * other linked list is the "type" list:
  39.  *  "in_use" - valid inode, hashed if i_nlink > 0
  40.  *  "dirty"  - valid inode, hashed if i_nlink > 0, dirty.
  41.  *  "unused" - ready to be re-used. Not hashed.
  42.  *
  43.  * A "dirty" list is maintained for each super block,
  44.  * allowing for low-overhead inode sync() operations.
  45.  */
  46.  
  47. static LIST_HEAD(inode_in_use);
  48. static LIST_HEAD(inode_unused);
  49. static struct list_head inode_hashtable[HASH_SIZE];
  50.  
  51. /*
  52.  * A simple spinlock to protect the list manipulations.
  53.  *
  54.  * NOTE! You also have to own the lock if you change
  55.  * the i_state of an inode while it is in use..
  56.  */
  57. spinlock_t inode_lock = SPIN_LOCK_UNLOCKED;
  58.  
  59. /*
  60.  * Statistics gathering..
  61.  */
  62. struct {
  63.     int nr_inodes;
  64.     int nr_free_inodes;
  65.     int dummy[5];
  66. } inodes_stat = {0, 0,};
  67.  
  68. int max_inodes;
  69.  
  70. /*
  71.  * Put the inode on the super block's dirty list.
  72.  *
  73.  * CAREFUL! We mark it dirty unconditionally, but
  74.  * move it onto the dirty list only if it is hashed.
  75.  * If it was not hashed, it will never be added to
  76.  * the dirty list even if it is later hashed, as it
  77.  * will have been marked dirty already.
  78.  *
  79.  * In short, make sure you hash any inodes _before_
  80.  * you start marking them dirty..
  81.  */
  82. void __mark_inode_dirty(struct inode *inode)
  83. {
  84.     struct super_block * sb = inode->i_sb;
  85.  
  86.     if (sb) {
  87.         spin_lock(&inode_lock);
  88.         if (!(inode->i_state & I_DIRTY)) {
  89.             inode->i_state |= I_DIRTY;
  90.             /* Only add valid (ie hashed) inodes to the dirty list */
  91.             if (!list_empty(&inode->i_hash)) {
  92.                 list_del(&inode->i_list);
  93.                 list_add(&inode->i_list, &sb->s_dirty);
  94.             }
  95.         }
  96.         spin_unlock(&inode_lock);
  97.     }
  98. }
  99.  
  100. static void __wait_on_inode(struct inode * inode)
  101. {
  102.     struct wait_queue wait = { current, NULL };
  103.  
  104.     add_wait_queue(&inode->i_wait, &wait);
  105. repeat:
  106.     current->state = TASK_UNINTERRUPTIBLE;
  107.     if (inode->i_state & I_LOCK) {
  108.         schedule();
  109.         goto repeat;
  110.     }
  111.     remove_wait_queue(&inode->i_wait, &wait);
  112.     current->state = TASK_RUNNING;
  113. }
  114.  
  115. static inline void wait_on_inode(struct inode *inode)
  116. {
  117.     if (inode->i_state & I_LOCK)
  118.         __wait_on_inode(inode);
  119. }
  120.  
  121. /*
  122.  * These are initializations that only need to be done
  123.  * once, because the fields are idempotent across use
  124.  * of the inode..
  125.  */
  126. static inline void init_once(struct inode * inode)
  127. {
  128.     memset(inode, 0, sizeof(*inode));
  129.     init_waitqueue(&inode->i_wait);
  130.     INIT_LIST_HEAD(&inode->i_hash);
  131.     INIT_LIST_HEAD(&inode->i_dentry);
  132.     sema_init(&inode->i_sem, 1);
  133.     sema_init(&inode->i_atomic_write, 1);
  134. }
  135.  
  136. static inline void write_inode(struct inode *inode)
  137. {
  138.     if (inode->i_sb && inode->i_sb->s_op && inode->i_sb->s_op->write_inode)
  139.         inode->i_sb->s_op->write_inode(inode);
  140. }
  141.  
  142. static inline void sync_one(struct inode *inode)
  143. {
  144.     if (inode->i_state & I_LOCK) {
  145.         spin_unlock(&inode_lock);
  146.         __wait_on_inode(inode);
  147.         spin_lock(&inode_lock);
  148.     } else {
  149.         list_del(&inode->i_list);
  150.         list_add(&inode->i_list, &inode_in_use);
  151.         /* Set I_LOCK, reset I_DIRTY */
  152.         inode->i_state ^= I_DIRTY | I_LOCK;
  153.         spin_unlock(&inode_lock);
  154.  
  155.         write_inode(inode);
  156.  
  157.         spin_lock(&inode_lock);
  158.         inode->i_state &= ~I_LOCK;
  159.         wake_up(&inode->i_wait);
  160.     }
  161. }
  162.  
  163. static inline void sync_list(struct list_head *head)
  164. {
  165.     struct list_head * tmp;
  166.  
  167.     while ((tmp = head->prev) != head)
  168.         sync_one(list_entry(tmp, struct inode, i_list));
  169. }
  170.  
  171. /*
  172.  * "sync_inodes()" goes through the super block's dirty list, 
  173.  * writes them out, and puts them back on the normal list.
  174.  */
  175. void sync_inodes(kdev_t dev)
  176. {
  177.     struct super_block * sb = sb_entry(super_blocks.next);
  178.  
  179.     /*
  180.      * Search the super_blocks array for the device(s) to sync.
  181.      */
  182.     spin_lock(&inode_lock);
  183.     for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.next)) {
  184.         if (!sb->s_dev)
  185.             continue;
  186.         if (dev && sb->s_dev != dev)
  187.             continue;
  188.  
  189.         sync_list(&sb->s_dirty);
  190.  
  191.         if (dev)
  192.             break;
  193.     }
  194.     spin_unlock(&inode_lock);
  195. }
  196.  
  197. /*
  198.  * Called with the spinlock already held..
  199.  */
  200. static void sync_all_inodes(void)
  201. {
  202.     struct super_block * sb = sb_entry(super_blocks.next);
  203.     for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.next)) {
  204.         if (!sb->s_dev)
  205.             continue;
  206.         sync_list(&sb->s_dirty);
  207.     }
  208. }
  209.  
  210. /*
  211.  * Needed by knfsd
  212.  */
  213. void write_inode_now(struct inode *inode)
  214. {
  215.     struct super_block * sb = inode->i_sb;
  216.  
  217.     if (sb) {
  218.         spin_lock(&inode_lock);
  219.         while (inode->i_state & I_DIRTY)
  220.             sync_one(inode);
  221.         spin_unlock(&inode_lock);
  222.     }
  223.     else
  224.         printk("write_inode_now: no super block\n");
  225. }
  226.  
  227. /*
  228.  * This is called by the filesystem to tell us
  229.  * that the inode is no longer useful. We just
  230.  * terminate it with extreme prejudice.
  231.  */
  232. void clear_inode(struct inode *inode)
  233. {
  234.     if (inode->i_nrpages)
  235.         truncate_inode_pages(inode, 0);
  236.     wait_on_inode(inode);
  237.     if (IS_QUOTAINIT(inode))
  238.         DQUOT_DROP(inode);
  239.     if (inode->i_sb && inode->i_sb->s_op && inode->i_sb->s_op->clear_inode)
  240.         inode->i_sb->s_op->clear_inode(inode);
  241.  
  242.     inode->i_state = 0;
  243. }
  244.  
  245. /*
  246.  * Dispose-list gets a local list, so it doesn't need to
  247.  * worry about list corruption. It releases the inode lock
  248.  * while clearing the inodes.
  249.  */
  250. static void dispose_list(struct list_head * head)
  251. {
  252.     struct list_head *next;
  253.     int count = 0;
  254.  
  255.     spin_unlock(&inode_lock);
  256.     next = head->next;
  257.     for (;;) {
  258.         struct list_head * tmp = next;
  259.         struct inode * inode;
  260.  
  261.         next = next->next;
  262.         if (tmp == head)
  263.             break;
  264.         inode = list_entry(tmp, struct inode, i_list);
  265.         clear_inode(inode);
  266.         count++;
  267.     }
  268.  
  269.     /* Add them all to the unused list in one fell swoop */
  270.     spin_lock(&inode_lock);
  271.     list_splice(head, &inode_unused);
  272.     inodes_stat.nr_free_inodes += count;
  273. }
  274.  
  275. /*
  276.  * Invalidate all inodes for a device.
  277.  */
  278. static int invalidate_list(struct list_head *head, struct super_block * sb, struct list_head * dispose)
  279. {
  280.     struct list_head *next;
  281.     int busy = 0;
  282.  
  283.     next = head->next;
  284.     for (;;) {
  285.         struct list_head * tmp = next;
  286.         struct inode * inode;
  287.  
  288.         next = next->next;
  289.         if (tmp == head)
  290.             break;
  291.         inode = list_entry(tmp, struct inode, i_list);
  292.         if (inode->i_sb != sb)
  293.             continue;
  294.         if (!inode->i_count) {
  295.             list_del(&inode->i_hash);
  296.             INIT_LIST_HEAD(&inode->i_hash);
  297.             list_del(&inode->i_list);
  298.             list_add(&inode->i_list, dispose);
  299.             continue;
  300.         }
  301.         busy = 1;
  302.     }
  303.     return busy;
  304. }
  305.  
  306. /*
  307.  * This is a two-stage process. First we collect all
  308.  * offending inodes onto the throw-away list, and in
  309.  * the second stage we actually dispose of them. This
  310.  * is because we don't want to sleep while messing
  311.  * with the global lists..
  312.  */
  313. int invalidate_inodes(struct super_block * sb)
  314. {
  315.     int busy;
  316.     LIST_HEAD(throw_away);
  317.  
  318.     spin_lock(&inode_lock);
  319.     busy = invalidate_list(&inode_in_use, sb, &throw_away);
  320.     busy |= invalidate_list(&sb->s_dirty, sb, &throw_away);
  321.     dispose_list(&throw_away);
  322.     spin_unlock(&inode_lock);
  323.  
  324.     return busy;
  325. }
  326.  
  327. /*
  328.  * This is called with the inode lock held. It searches
  329.  * the in-use for freeable inodes, which are moved to a
  330.  * temporary list and then placed on the unused list by
  331.  * dispose_list. 
  332.  *
  333.  * We don't expect to have to call this very often.
  334.  *
  335.  * N.B. The spinlock is released during the call to
  336.  *      dispose_list.
  337.  */
  338. #define CAN_UNUSE(inode) \
  339.     (((inode)->i_count | (inode)->i_state) == 0)
  340. #define INODE(entry)    (list_entry(entry, struct inode, i_list))
  341.  
  342. static int free_inodes(void)
  343. {
  344.     struct list_head list, *entry, *freeable = &list;
  345.     int found = 0;
  346.  
  347.     INIT_LIST_HEAD(freeable);
  348.     entry = inode_in_use.next;
  349.     while (entry != &inode_in_use) {
  350.         struct list_head *tmp = entry;
  351.  
  352.         entry = entry->next;
  353.         if (!CAN_UNUSE(INODE(tmp)))
  354.             continue;
  355.         list_del(tmp);
  356.         list_del(&INODE(tmp)->i_hash);
  357.         INIT_LIST_HEAD(&INODE(tmp)->i_hash);
  358.         list_add(tmp, freeable);
  359.         found = 1;
  360.     }
  361.  
  362.     if (found) {
  363.         dispose_list(freeable);
  364.         found = 1;    /* silly compiler */
  365.     }
  366.  
  367.     return found;
  368. }
  369.  
  370. /*
  371.  * Searches the inodes list for freeable inodes,
  372.  * shrinking the dcache before (and possible after,
  373.  * if we're low)
  374.  */
  375. static void try_to_free_inodes(int goal)
  376. {
  377.     /*
  378.      * First stry to just get rid of unused inodes.
  379.      *
  380.      * If we can't reach our goal that way, we'll have
  381.      * to try to shrink the dcache and sync existing
  382.      * inodes..
  383.      */
  384.     free_inodes();
  385.     goal -= inodes_stat.nr_free_inodes;
  386.     if (goal > 0) {
  387.         spin_unlock(&inode_lock);
  388.         select_dcache(goal, 0);
  389.         prune_dcache(goal);
  390.         spin_lock(&inode_lock);
  391.         sync_all_inodes();
  392.         free_inodes();
  393.     }
  394. }
  395.  
  396. /*
  397.  * This is the externally visible routine for
  398.  * inode memory management.
  399.  */
  400. void free_inode_memory(int goal)
  401. {
  402.     spin_lock(&inode_lock);
  403.     free_inodes();
  404.     spin_unlock(&inode_lock);
  405. }
  406.  
  407.  
  408. /*
  409.  * This is called with the spinlock held, but releases
  410.  * the lock when freeing or allocating inodes.
  411.  * Look out! This returns with the inode lock held if
  412.  * it got an inode..
  413.  *
  414.  * We do inode allocations two pages at a time to reduce
  415.  * fragmentation.
  416.  */
  417. #define INODE_PAGE_ORDER    1
  418. #define INODE_ALLOCATION_SIZE    (PAGE_SIZE << INODE_PAGE_ORDER)
  419. #define INODES_PER_ALLOCATION    (INODE_ALLOCATION_SIZE/sizeof(struct inode))
  420.  
  421. static struct inode * grow_inodes(void)
  422. {
  423.     struct inode * inode;
  424.  
  425.     /*
  426.      * Check whether to restock the unused list.
  427.      */
  428.     if (inodes_stat.nr_inodes > max_inodes) {
  429.         struct list_head *tmp;
  430.         try_to_free_inodes(inodes_stat.nr_inodes >> 2);
  431.         tmp = inode_unused.next;
  432.         if (tmp != &inode_unused) {
  433.             inodes_stat.nr_free_inodes--;
  434.             list_del(tmp);
  435.             inode = list_entry(tmp, struct inode, i_list);
  436.             return inode;
  437.         }
  438.     }
  439.         
  440.     spin_unlock(&inode_lock);
  441.     inode = (struct inode *)__get_free_pages(GFP_KERNEL,INODE_PAGE_ORDER);
  442.     if (inode) {
  443.         int size;
  444.         struct inode * tmp;
  445.  
  446.         size = INODE_ALLOCATION_SIZE - 2*sizeof(struct inode);
  447.         tmp = inode;
  448.         spin_lock(&inode_lock);
  449.         do {
  450.             tmp++;
  451.             init_once(tmp);
  452.             list_add(&tmp->i_list, &inode_unused);
  453.             size -= sizeof(struct inode);
  454.         } while (size >= 0);
  455.         init_once(inode);
  456.         /*
  457.          * Update the inode statistics
  458.          */
  459.         inodes_stat.nr_inodes += INODES_PER_ALLOCATION;
  460.         inodes_stat.nr_free_inodes += INODES_PER_ALLOCATION - 1;
  461.         return inode;
  462.     }
  463.  
  464.     /*
  465.      * If the allocation failed, do an extensive pruning of 
  466.      * the dcache and then try again to free some inodes.
  467.      */
  468.     prune_dcache(inodes_stat.nr_inodes >> 2);
  469.  
  470.     spin_lock(&inode_lock);
  471.     free_inodes();
  472.     {
  473.         struct list_head *tmp = inode_unused.next;
  474.         if (tmp != &inode_unused) {
  475.             inodes_stat.nr_free_inodes--;
  476.             list_del(tmp);
  477.             inode = list_entry(tmp, struct inode, i_list);
  478.             return inode;
  479.         }
  480.     }
  481.     spin_unlock(&inode_lock);
  482.  
  483.     printk("grow_inodes: allocation failed\n");
  484.     return NULL;
  485. }
  486.  
  487. /*
  488.  * Called with the inode lock held.
  489.  */
  490. static struct inode * find_inode(struct super_block * sb, unsigned long ino, struct list_head *head)
  491. {
  492.     struct list_head *tmp;
  493.     struct inode * inode;
  494.  
  495.     tmp = head;
  496.     for (;;) {
  497.         tmp = tmp->next;
  498.         inode = NULL;
  499.         if (tmp == head)
  500.             break;
  501.         inode = list_entry(tmp, struct inode, i_hash);
  502.         if (inode->i_sb != sb)
  503.             continue;
  504.         if (inode->i_ino != ino)
  505.             continue;
  506.         inode->i_count++;
  507.         break;
  508.     }
  509.     return inode;
  510. }
  511.  
  512. /*
  513.  * This just initializes the inode fields
  514.  * to known values before returning the inode..
  515.  *
  516.  * i_sb, i_ino, i_count, i_state and the lists have
  517.  * been initialized elsewhere..
  518.  */
  519. void clean_inode(struct inode *inode)
  520. {
  521.     memset(&inode->u, 0, sizeof(inode->u));
  522.     inode->i_sock = 0;
  523.     inode->i_op = NULL;
  524.     inode->i_nlink = 1;
  525.     inode->i_writecount = 0;
  526.     inode->i_size = 0;
  527.     memset(&inode->i_dquot, 0, sizeof(inode->i_dquot));
  528.     sema_init(&inode->i_sem, 1);
  529. }
  530.  
  531. /*
  532.  * This is called by things like the networking layer
  533.  * etc that want to get an inode without any inode
  534.  * number, or filesystems that allocate new inodes with
  535.  * no pre-existing information.
  536.  */
  537. struct inode * get_empty_inode(void)
  538. {
  539.     static unsigned long last_ino = 0;
  540.     struct inode * inode;
  541.     struct list_head * tmp;
  542.  
  543.     spin_lock(&inode_lock);
  544.     tmp = inode_unused.next;
  545.     if (tmp != &inode_unused) {
  546.         list_del(tmp);
  547.         inodes_stat.nr_free_inodes--;
  548.         inode = list_entry(tmp, struct inode, i_list);
  549. add_new_inode:
  550.         list_add(&inode->i_list, &inode_in_use);
  551.         inode->i_sb = NULL;
  552.         inode->i_dev = 0;
  553.         inode->i_ino = ++last_ino;
  554.         inode->i_flags = 0;
  555.         inode->i_count = 1;
  556.         inode->i_state = 0;
  557.         spin_unlock(&inode_lock);
  558.         clean_inode(inode);
  559.         return inode;
  560.     }
  561.  
  562.     /*
  563.      * Warning: if this succeeded, we will now
  564.      * return with the inode lock.
  565.      */
  566.     inode = grow_inodes();
  567.     if (inode)
  568.         goto add_new_inode;
  569.  
  570.     return inode;
  571. }
  572.  
  573. /*
  574.  * This is called with the inode lock held.. Be careful.
  575.  *
  576.  * We no longer cache the sb_flags in i_flags - see fs.h
  577.  *    -- rmk@arm.uk.linux.org
  578.  */
  579. static struct inode * get_new_inode(struct super_block *sb, unsigned long ino, struct list_head *head)
  580. {
  581.     struct inode * inode;
  582.     struct list_head * tmp = inode_unused.next;
  583.  
  584.     if (tmp != &inode_unused) {
  585.         list_del(tmp);
  586.         inodes_stat.nr_free_inodes--;
  587.         inode = list_entry(tmp, struct inode, i_list);
  588. add_new_inode:
  589.         list_add(&inode->i_list, &inode_in_use);
  590.         list_add(&inode->i_hash, head);
  591.         inode->i_sb = sb;
  592.         inode->i_dev = sb->s_dev;
  593.         inode->i_ino = ino;
  594.         inode->i_flags = 0;
  595.         inode->i_count = 1;
  596.         inode->i_state = I_LOCK;
  597.         spin_unlock(&inode_lock);
  598.  
  599.         clean_inode(inode);
  600.         sb->s_op->read_inode(inode);
  601.  
  602.         /*
  603.          * This is special!  We do not need the spinlock
  604.          * when clearing I_LOCK, because we're guaranteed
  605.          * that nobody else tries to do anything about the
  606.          * state of the inode when it is locked, as we
  607.          * just created it (so there can be no old holders
  608.          * that haven't tested I_LOCK).
  609.          */
  610.         inode->i_state &= ~I_LOCK;
  611.         wake_up(&inode->i_wait);
  612.  
  613.         return inode;
  614.     }
  615.  
  616.     /*
  617.      * We need to expand. Note that "grow_inodes()" will
  618.      * release the spinlock, but will return with the lock 
  619.      * held again if the allocation succeeded.
  620.      */
  621.     inode = grow_inodes();
  622.     if (inode) {
  623.         /* We released the lock, so.. */
  624.         struct inode * old = find_inode(sb, ino, head);
  625.         if (!old)
  626.             goto add_new_inode;
  627.         list_add(&inode->i_list, &inode_unused);
  628.         inodes_stat.nr_free_inodes++;
  629.         spin_unlock(&inode_lock);
  630.         wait_on_inode(old);
  631.         return old;
  632.     }
  633.     return inode;
  634. }
  635.  
  636. static inline unsigned long hash(struct super_block *sb, unsigned long i_ino)
  637. {
  638.     unsigned long tmp = i_ino | (unsigned long) sb;
  639.     tmp = tmp + (tmp >> HASH_BITS) + (tmp >> HASH_BITS*2);
  640.     return tmp & HASH_MASK;
  641. }
  642.  
  643. struct inode *iget(struct super_block *sb, unsigned long ino)
  644. {
  645.     struct list_head * head = inode_hashtable + hash(sb,ino);
  646.     struct inode * inode;
  647.  
  648.     spin_lock(&inode_lock);
  649.     inode = find_inode(sb, ino, head);
  650.     if (inode) {
  651.         spin_unlock(&inode_lock);
  652.         wait_on_inode(inode);
  653.         return inode;
  654.     }
  655.     /*
  656.      * get_new_inode() will do the right thing, releasing
  657.      * the inode lock and re-trying the search in case it
  658.      * had to block at any point.
  659.      */
  660.     return get_new_inode(sb, ino, head);
  661. }
  662.  
  663. void insert_inode_hash(struct inode *inode)
  664. {
  665.     struct list_head *head = inode_hashtable + hash(inode->i_sb, inode->i_ino);
  666.     spin_lock(&inode_lock);
  667.     list_add(&inode->i_hash, head);
  668.     spin_unlock(&inode_lock);
  669. }
  670.  
  671. void remove_inode_hash(struct inode *inode)
  672. {
  673.     spin_lock(&inode_lock);
  674.     list_del(&inode->i_hash);
  675.     INIT_LIST_HEAD(&inode->i_hash);
  676.     spin_unlock(&inode_lock);
  677. }
  678.  
  679. void iput(struct inode *inode)
  680. {
  681.     if (inode) {
  682.         struct super_operations *op = NULL;
  683.  
  684.         if (inode->i_sb && inode->i_sb->s_op)
  685.             op = inode->i_sb->s_op;
  686.         if (op && op->put_inode)
  687.             op->put_inode(inode);
  688.  
  689.         spin_lock(&inode_lock);
  690.         if (!--inode->i_count) {
  691.             if (!inode->i_nlink) {
  692.                 list_del(&inode->i_hash);
  693.                 INIT_LIST_HEAD(&inode->i_hash);
  694.                 list_del(&inode->i_list);
  695.                 INIT_LIST_HEAD(&inode->i_list);
  696.                 if (op && op->delete_inode) {
  697.                     void (*delete)(struct inode *) = op->delete_inode;
  698.                     spin_unlock(&inode_lock);
  699.                     delete(inode);
  700.                     spin_lock(&inode_lock);
  701.                 }
  702.             }
  703.             if (list_empty(&inode->i_hash)) {
  704.                 list_del(&inode->i_list);
  705.                 INIT_LIST_HEAD(&inode->i_list);
  706.                 spin_unlock(&inode_lock);
  707.                 clear_inode(inode);
  708.                 spin_lock(&inode_lock);
  709.                 list_add(&inode->i_list, &inode_unused);
  710.                 inodes_stat.nr_free_inodes++;
  711.             }
  712.             else if (!(inode->i_state & I_DIRTY)) {
  713.                 list_del(&inode->i_list);
  714.                 list_add(&inode->i_list, &inode_in_use);
  715.             }
  716. #ifdef INODE_PARANOIA
  717. if (inode->i_flock)
  718. printk(KERN_ERR "iput: inode %s/%ld still has locks!\n",
  719. kdevname(inode->i_dev), inode->i_ino);
  720. if (!list_empty(&inode->i_dentry))
  721. printk(KERN_ERR "iput: device %s inode %ld still has aliases!\n",
  722. kdevname(inode->i_dev), inode->i_ino);
  723. if (inode->i_count)
  724. printk(KERN_ERR "iput: device %s inode %ld count changed, count=%d\n",
  725. kdevname(inode->i_dev), inode->i_ino, inode->i_count);
  726. if (atomic_read(&inode->i_sem.count) != 1)
  727. printk(KERN_ERR "iput: Aieee, semaphore in use inode %s/%ld, count=%d\n",
  728. kdevname(inode->i_dev), inode->i_ino, atomic_read(&inode->i_sem.count));
  729. if (atomic_read(&inode->i_atomic_write.count) != 1)
  730. printk(KERN_ERR "iput: Aieee, atomic write semaphore in use inode %s/%ld, count=%d\n",
  731. kdevname(inode->i_dev), inode->i_ino, atomic_read(&inode->i_sem.count));
  732. #endif
  733.         }
  734.         if (inode->i_count > (1<<31)) {
  735.             printk(KERN_ERR "iput: inode %s/%ld count wrapped\n",
  736.                 kdevname(inode->i_dev), inode->i_ino);
  737.         }
  738.         spin_unlock(&inode_lock);
  739.     }
  740. }
  741.  
  742. int bmap(struct inode * inode, int block)
  743. {
  744.     if (inode->i_op && inode->i_op->bmap)
  745.         return inode->i_op->bmap(inode, block);
  746.     return 0;
  747. }
  748.  
  749. /*
  750.  * Initialize the hash tables and default
  751.  * value for max inodes
  752.  */
  753. #define MAX_INODE (12288)
  754.  
  755. void __init inode_init(void)
  756. {
  757.     int i, max;
  758.     struct list_head *head = inode_hashtable;
  759.  
  760.     i = HASH_SIZE;
  761.     do {
  762.         INIT_LIST_HEAD(head);
  763.         head++;
  764.         i--;
  765.     } while (i);
  766.  
  767.     /* Initial guess at reasonable inode number */
  768.     max = num_physpages >> 1;
  769.     if (max > MAX_INODE)
  770.         max = MAX_INODE;
  771.     max_inodes = max;
  772. }
  773.  
  774. /* This belongs in file_table.c, not here... */
  775. int fs_may_remount_ro(struct super_block *sb)
  776. {
  777.     struct file *file;
  778.  
  779.     /* Check that no files are currently opened for writing. */
  780.     for (file = inuse_filps; file; file = file->f_next) {
  781.         struct inode *inode;
  782.         if (!file->f_dentry)
  783.             continue;
  784.         inode = file->f_dentry->d_inode;
  785.         if (!inode || inode->i_sb != sb)
  786.             continue;
  787.  
  788.         /* File with pending delete? */
  789.         if (inode->i_nlink == 0)
  790.             return 0;
  791.  
  792.         /* Writable file? */
  793.         if (S_ISREG(inode->i_mode) && (file->f_mode & FMODE_WRITE))
  794.             return 0;
  795.     }
  796.     return 1; /* Tis' cool bro. */
  797. }
  798.  
  799. void update_atime (struct inode *inode)
  800. {
  801.     if ( IS_NOATIME (inode) ) return;
  802.     if ( IS_NODIRATIME (inode) && S_ISDIR (inode->i_mode) ) return;
  803.     if ( IS_RDONLY (inode) ) return;
  804.     inode->i_atime = CURRENT_TIME;
  805.     mark_inode_dirty (inode);
  806. }   /*  End Function update_atime  */
  807.